package com.tang.sso.controller.user;

import com.tang.sso.entity.TbUser;
import com.tang.sso.service.UserService;
import com.tang.sso.util.Result.Result;
import com.tang.sso.util.Result.ResultCodeEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author zjg
 * @date 2018/8/14 8:19
 * @Description
 */
@Slf4j
@RestController
@RequestMapping("/user")
public class UserController {

    @Resource
    private UserService userService;

    /**
     * 判断是否该用户已经存在，若存在，则不插入；不存在就插入
     *
     * @param tbUser
     * @return
     */
    @PutMapping
    public Result insertUser(@RequestBody TbUser tbUser) {
        boolean boo = userService.insertUser(tbUser);
        if (boo) {
            return new Result(ResultCodeEnum.INSERTSUCCESS, "添加成功");
        }
        return new Result(ResultCodeEnum.INSERTFAIL, "用户已存在");
    }
}
